
//
//  YKStatusToolBar.m
//  youkan
//
//  Created by mac mini on 16/3/3.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKStatusToolBar.h"
#import "YKWBStatues.h"
@interface YKStatusToolBar()
@property(nonatomic,strong)NSMutableArray *btns;
@property(nonatomic,strong)NSMutableArray *divideVs;
@property(nonatomic,weak)UIButton *retweet;
@property(nonatomic,weak)UIButton *comment;
@property(nonatomic,weak)UIButton *unlink;
@end
@implementation YKStatusToolBar
-(NSMutableArray *)btns{
    if (!_btns) {
        _btns =[NSMutableArray array];
    }
    return _btns;
}
-(NSMutableArray *)divideVs{
    if (!_divideVs) {
        _divideVs =[NSMutableArray array];
    }
    return _divideVs;
}
-(instancetype)initWithFrame:(CGRect)frame{
    if (self =[super initWithFrame:frame]) {
        [self setUpAllChildView] ;
        self.image =[UIImage imageWithStretchableName:@"timeline_card_bottom_background"];
//        self.backgroundColor =[UIColor whiteColor];
    }
    return self;
}
//添加所有子控件
-(void)setUpAllChildView{
// 转发
    self.retweet =[self setUpbuttonWithIcon:[UIImage imageNamed:@"timeline_icon_retweet"] Title:@"转发"];
    //评论
    self.comment =[self setUpbuttonWithIcon:[UIImage imageNamed:@"timeline_icon_comment"] Title:@"评论"];
    //赞
    self.unlink =[self setUpbuttonWithIcon:[UIImage imageNamed:@"timeline_icon_unlike"] Title:@"赞"];
    for (int i=0; i<2; i++) {
        UIImageView *divideV=[[UIImageView  alloc] initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
        [self addSubview:divideV];
        [self.divideVs addObject:divideV];
    }
}
-(UIButton *)setUpbuttonWithIcon:(UIImage *)icon Title:(NSString*)title{
    UIButton *retweet =[UIButton buttonWithType:UIButtonTypeCustom];
    [retweet setTitle:title forState:UIControlStateNormal];
    [retweet setImage:icon forState:UIControlStateNormal];
    [retweet setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    retweet.titleLabel.font =[UIFont systemFontOfSize:12];
    [retweet setImageEdgeInsets:UIEdgeInsetsMake(0, 0,0 , 5)];
//    相对最开始的位置
//    retweet.titleEdgeInsets =UIEdgeInsetsMake(0, 5, 0, 0);
    [self.btns addObject:retweet];
    [self addSubview:retweet];
    return retweet;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat w= SCWidth/self.btns.count;
    CGFloat H= self.height;
    CGFloat X =0;
    CGFloat Y= 0;
    for (NSInteger i=0; i<self.btns.count; i++) {
        UIButton *btn =self.btns[i];
        X=i*w;
        btn.frame =CGRectMake(X, Y, w, H);
    }
    
    NSInteger i=1;
    for (UIImageView *divdie in self.divideVs) {
        UIButton *btn =self.btns[i];
        divdie.x=btn.x;
        i++;
    }
}

-(void)setStatus:(YKWBStatues *)status{
    _status =status;
    [self setBtn:_retweet Tite:status.reposts_count];
    [self setBtn:_comment Tite:status.comments_count];
    [self setBtn:_unlink Tite:status.attitudes_count];
}
-(void)setBtn:(UIButton*)btn Tite:(int)count{
    NSString *title =btn.titleLabel.text;
    if (count) {
        if (count>10000) {
            CGFloat floatCount =count/10000.0;
            title =[NSString stringWithFormat:@"%.1fw",floatCount];
            title=[title stringByReplacingOccurrencesOfString:@".0" withString:@""];
        }else{
            title =[NSString stringWithFormat:@"%d",count];
        }
    }
    [btn setTitle:title forState:UIControlStateNormal];
}
@end












